package com.nutricia.core.service.impl;

import com.nutricia.common.dal.persistant.CmsSystemMenu;
import com.nutricia.core.ex.BizErrorCode;
import com.nutricia.core.ex.BizException;
import com.nutricia.core.model.domain.CmsSystemMenuDO;
import com.nutricia.core.service.SystemMenuService;
import com.nutricia.core.service.convertor.SystemMenuServiceConvertor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统菜单
 *
 * @author: huangsheng
 * @date: 2017/10/23
 */
@Service("systemMenuService")
public class SystemMenuServiceImpl extends AbstractServiceImpl implements SystemMenuService {

    /**
     * 获取菜单树数据
     *
     * @author: huangsheng
     * @date: 2017/10/24 下午4:13
     */
    @Override
    public List<CmsSystemMenuDO> getMenuTreeData() {
        try {
            List<CmsSystemMenu> cmsSystemMenus = systemMenuMapper.queryMenuTree();
            logger.info("获取到菜单数据，菜单数据长度为： {}", cmsSystemMenus.size());
            return SystemMenuServiceConvertor.convertToCmsSystemMenuDOs(cmsSystemMenus);
        } catch (Exception e) {
            logger.error("获取菜单树数据查询数据库异常: {}", e);
            throw new BizException(BizErrorCode.SYSTEM_ERROR, "系统异常");
        }

    }
}
